package org.crystalcore;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

import static org.crystalcore.ShulkerDupe.shulkerBoxCounts;

public final class CrystalCore extends JavaPlugin implements Listener {
    public static Integer shulkercount;
    public static Boolean total_detection;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        boolean detection = getConfig().getBoolean("32k-detection.enable");
        total_detection = getConfig().getBoolean("32k-detection.total-ban");
        boolean shulkerdupe = getConfig().getBoolean("shulker-dupe.enable");
        shulkercount = getConfig().getInt("shulker-dupe.count");

        // 注册事件监听器
        if (shulkerdupe) {
            getServer().getPluginManager().registerEvents(new ShulkerDupe(), this);
        }
        if (detection) {
            getServer().getPluginManager().registerEvents(new DamageLimiter(), this);
        }
//        getCommand("shulkerdupe").setExecutor(this);

    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("crystalcore")) {
            if (args.length == 1 && args[0].equalsIgnoreCase("shulkerdupe")) {
                Player player = (Player) sender;
                player.sendMessage("您还需要放置" + String.valueOf(shulkercount - shulkerBoxCounts.getOrDefault(player, 0)) + "个潜影盒来完成下一次复制");
                return true;
            }
        }
        return false;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        LinkedList<String> tips = new LinkedList<>();
        tips.add(0,"shulkerdupe");
        return tips;
    }
}

